package com.grts.mall.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.grts.mall.mapper.ProductMapper;
import com.grts.mall.pojo.Product;
import com.grts.mall.pojo.vo.ProductSearchConditionVo;
import com.grts.mall.pojo.vo.SerachCondtion;
import com.grts.mall.pojo.vo.SerachResult;

@Service
public class ProductServiceImpl implements ProductService{
	
	@Autowired
	private ProductMapper productMapper;

	@Override
	public List<Product> findNewProduct(Integer num) {
		return this.productMapper.selectNewProducts(num);
	}

	@Override
	public List<Product> findHotProduct(Integer num) {
		
		return this.productMapper.selectHotPorduct(num);
	}

	@Override
	public List<Product> findall(ProductSearchConditionVo vo) {
		
		List<Product> list = this.productMapper.selectPageList(vo);
		return list;
	}

	@Override
	public SerachResult serach(SerachCondtion vo) {
		vo.setQ("%"+vo.getQ()+"%");
		List<Product> data = this.productMapper.selectPageListByKeyWord(vo);
		long totalRows = this.productMapper.countByKeyword(vo);
		SerachResult seracr = new SerachResult();
		seracr.setData(data);
		seracr.setTotalRows(totalRows);
		return seracr;
	}

	@Override
	public Product findById(Long pid) {
		Product pro = this.productMapper.selectByPrimaryKey(pid);
		return pro;
	}


}
